<template>
    <div class="container">
        <div class="content_wrapper">
            <div class="lyecs-table-list-warp">
                <div class="list-table-tool lyecs-search-warp">
                    <el-form :model="filterParams">
                        <div class="list-table-tool-row">
                            <div class="list-table-tool-col">
                                <el-space>
                                    <el-select v-model="filterParams.pay_status" clearable placeholder="请选择状态">
                                        <el-option :value="0" label="未支付"/>
                                        <el-option :value="1" label="已支付"/>
                                    </el-select>
                                    <el-input v-model="filterParams.keyword" name="keyword" placeholder="输入订单号">
                                        <template #append>
                                            <el-button @click="onSearchSubmit"><span class="iconfont icon-chakan1"></span>
                                            </el-button>
                                        </template>
                                    </el-input>
                                </el-space>
                            </div>
                        </div>
                    </el-form>
                </div>
                <div class="table-container">
                    <a-spin :spinning="loading">
                        <el-table :data="filterState" :loading="loading" :total="total" row-key="paylog_id"
                                  @sort-change="onSortChange"> 
                            <el-table-column label="退款信息" prop="aftersales_sn">
                                <template #default="{ row }">
                                    <div  style="display: flex;justify-content: space-between;align-items: center">
                                        <DialogForm :params="{ act: 'detail', id: row.refund.aftersale_id, type: 2 }" isDrawer
                                                    path="order/aftersales/Info"
                                                    :title="'售后详情 ' + row.refund.aftersales.aftersales_sn" width="800px"
                                                    @okCallback="loadFilter" :showClose="false" :showOnOk="false">
                                                    售后编号：<a>{{row.refund.aftersales.aftersales_sn}}</a>
                                        </DialogForm>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column label="退款方式" prop="refund_type_text"></el-table-column>
                            <el-table-column label="退款金额" prop="refund_amount"></el-table-column>
                            <el-table-column :width="160" label="退款时间" prop="add_time" sortable="custom"></el-table-column>
                            <template #empty>
                                <div class="empty-warp">
                                    <div v-if="!loading" class="empty-bg">暂无数据</div>
                                </div>
                            </template>
                        </el-table>
                    </a-spin>
                    <div v-if="total > 0" class="pagination-con">
                        <Pagination v-model:page="filterParams.page" v-model:size="filterParams.size" :total="total"
                                    @callback="loadFilter"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import '@/style/css/list.less'
import {DialogForm} from '@/components/dialog'
import {onMounted, reactive, ref} from 'vue';
import {Pagination} from '@/components/list';
import {message} from 'ant-design-vue'
import {useConfigStore} from "@/store/config";
import {RedundLogFilterParams, RedundLogFilterState} from '@/types/finance/refundLog';
import {getRedundLogList} from "@/api/finance/refundLog";

const config:any = useConfigStore();
// 基本参数定义
const filterState = ref(<RedundLogFilterState[]>[]);
const loading = ref<boolean>(true);
const total = ref<number>(0);
const filterParams = reactive<RedundLogFilterParams>({   //初使化用于查询的参数
    page: 1,
    size: config.get('page_size'),
    sort_field: '',
    sort_order: '',
    keyword: '',
    pay_status: 1,
});
// 获取列表的查询结果
const loadFilter = async () => {
    loading.value = true;
    try {
        const result = await getRedundLogList({...filterParams});
        filterState.value = result.filter_result;
        total.value = result.total;
    } catch (error:any) {
        message.error(error.message);
    } finally {
        loading.value = false;
    }

}
onMounted(() => {
    loadFilter();
});

// 参数查询
const onSearchSubmit = () => {
    loadFilter()
};
// 修改排序
const onSortChange = ({prop, order}: { prop: string; order?: string }) => {
    filterParams.sort_field = prop;
    filterParams.sort_order = order == 'ascending' ? 'asc' : order == 'descending' ? 'desc' : '';
    loadFilter();
};


</script>
